package com.enqualcomm.kids.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.enqualcomm.kids.R;

import common.utils.DensityUtil;
import common.utils.PlatformUtil;

/**
 * Created by Sunzhigang on 2015/11/3.
 */
public class DeleteBillMessageDialog extends Dialog {
    boolean isToCleanAll;
    int position;
    Context context;
    DeleteBillMessageCallBack deleteBillMessageCallBack;

    public DeleteBillMessageDialog(Context context, boolean isToCleanAll, int position,DeleteBillMessageCallBack deleteBillMessageCallBack) {
        super(context);
        this.context = context;
        this.isToCleanAll = isToCleanAll;
        this.position = position;
        this.deleteBillMessageCallBack = deleteBillMessageCallBack;
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.setContentView(R.layout.dialog_cancelterminal);

        setDialogAttributes();

        initDialogView();
    }

    public void setDialogAttributes() {
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        PlatformUtil.windowWidth((Activity) context);
//        lp.width = GlobalParams.dialogWidth; // 宽度
        lp.width= PlatformUtil.windowWidth((Activity) context)- DensityUtil.dip2px(context, 30);
        // lp.alpha = 0.9f; // 透明度

        dialogWindow.setAttributes(lp);
        dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }

    public void initDialogView() {
        final TextView myTerminal = (TextView) findViewById(R.id.myTerminal);
        myTerminal.setText(context.getString(R.string.delete));
        TextView dialog_msg_tv = (TextView) findViewById(R.id.dialog_msg_tv);
        if (isToCleanAll){
            dialog_msg_tv.setText(context.getString(R.string.confirm_clear_message));
        }else {
            dialog_msg_tv.setText(context.getString(R.string.confirm_clear_the_message));
        }


        findViewById(R.id.sureBtn).setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View arg0, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    dismiss();
                 deleteBillMessageCallBack.deleteBillMessage(isToCleanAll,position);
                }
                return false;
            }
        });

        findViewById(R.id.cancelBtn).setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View arg0, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    dismiss();
                }
                return false;
            }
        });
    }
}
